package com.mmall.concurrency.example.sync;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Slf4j
public class SynchronizedExample2 {

    public static void test1(){
        synchronized (SynchronizedExample2.class){
            for(int i=0;i<10;i++){
                log.info("test-{}",i);
            }
        }
    }

    public synchronized static void test02(){
        for (int i=0;i<10;i++){
            log.info("test-{}",i);
        }
    }

    public static void main(String[] args) {
        SynchronizedExample2 example1=new SynchronizedExample2();
        ExecutorService exe= Executors.newCachedThreadPool();
        exe.execute(()->{
            example1.test1();
        });
        exe.execute(()->{
            example1.test1();
        });
    }
}
